<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>MultiLanguage</title>
</head>
<body>
	<select onchange="changLanguage(this)" id="langSelect">
		<option value="zh_CN">中文</option>
		<option value="en_US">English</option>
		<option value="zh_TW">繁体中文</option>
	</select>

	<fmt:setLocale value="zh_CN" />
	<c:if test="${not empty lang }">
		<fmt:setLocale value="${lang }" />
	</c:if>

	<fmt:bundle basename="i18n">
		<h1>
			test:
			<fmt:message key="common.copyright"></fmt:message>
		</h1>
	</fmt:bundle>
	<h2>session:${lang}</h2>
	<input type="text" onClick="changeSession()">

	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript">
		var currentLang;
		$(document).ready(function(){
			currentLang="<%=session.getAttribute("lang")%>";
			if(currentLang!=null){
				$("#langSelect").val(currentLang);
			}else{
				alert(currentLang);
				$("#langSelect").val("zh_CN");
			}
		});
		
		function changLanguage(obj) {

			var lang = obj.options[obj.selectedIndex].value;
			var url = "test?lang="+lang;
			$.ajax({
				type : "GET",
				url : url,
				success : function(data) {
					
					location.reload();
				},
				error : function(err) {
					alert(err.responseText);
				},
			});
		}
	</script>
</body>
</html>